package com.ccn.elasticsearch.controller;

import com.ccn.elasticsearch.entity.Content;
import com.ccn.elasticsearch.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author wangxy
 * @date 2021/7/8 10:51
 */
@Controller
public class EsContorller {

    @Autowired
    private ContentService service;
    @GetMapping({"/","index"})
    public String search(){

        return "index";
    }
    @ResponseBody
    @GetMapping("/search/{keyword}/{from}/{size}")
    public List<Map<String, Object>> searchHigh(@PathVariable("keyword")String keyword,@PathVariable("from")int from,@PathVariable("size")int size ) throws IOException {
//        List<Map<String, Object>> maps = service.search(keyword,from,size);
        List<Map<String, Object>> maps = service.searchContentHighlighter(keyword,from,size);
        System.out.println(maps);
        return maps;
    }
}
